#include "WindowInput.h"
#include "Fysics/System/VirtualMachine.h"
#include "Fysics/GraphicsAPI/OpenGL/OpenGLWindow.h"

#include <GLFW/glfw3.h>

namespace Fysics
{
#ifdef FAR_IMPLEMENT_OPENGL
    bool WindowInput::IsKeyPressed(int keycode)
    {
        GLFWwindow* window = (GLFWwindow*)VirtualMachine::GetInstance()->GetWindow()->GetNativeWindow();
        int key_state = glfwGetKey(window, keycode);
        return key_state == GLFW_PRESS || key_state == GLFW_REPEAT;
    }

    bool WindowInput::IsMouseButtonPressed(int button)
    {
        GLFWwindow* window = (GLFWwindow*)VirtualMachine::GetInstance()->GetWindow()->GetNativeWindow();
        int btn_state = glfwGetMouseButton(window, button);
        return btn_state == GLFW_PRESS;
    }

    glm::vec2 WindowInput::GetMousePos()
    {
        GLFWwindow* window = (GLFWwindow*)VirtualMachine::GetInstance()->GetWindow()->GetNativeWindow();
        double xpos, ypos;
        glfwGetCursorPos(window, &xpos, &ypos);
        return glm::vec2(xpos, ypos);
    }
#endif
}
